
//实例内部类
/*
class OutClass{
    //成员变量
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 =3;//类变量
    //构造方法
    public OutClass(){
        System.out.println("外部类的构造方法！");
    }
    //实例内部类
    class InsideClass{
        //成员变量
        public int data1 = 4;
        private int data2 = 5;
        public static final int date3 = 6;//必须用 final 修饰为常量，必须初始化
        //构造方法
        public InsideClass(){
            System.out.println("实例内部类的构造方法！");
        }
        //成员方法
        public void fun2(){
            System.out.println(OutClass.this.data1);//访问外部
            System.out.println(data2);//优先访问内部
            System.out.println("实例内部类的成员方法");
        }
    }
    //成员方法
    public void fun1(){
        OutClass.InsideClass inside = new InsideClass();//外部类中需要先创建对象内部类对象
        System.out.println(inside.data1);//在外部类中访问内部类成员
        System.out.println(inside.data2);
        System.out.println("外部类的成员方法！");
    }

}
public class Test{
    public static void main(String[] args){
        OutClass out = new OutClass();
        OutClass.InsideClass inside = out.new InsideClass();//必须建立在外部类对象的前提的下
    }
}*/

/*
class OutClass{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    public OutClass(){
        System.out.println("外部类的构造方法！");
    }
    static class InsideClass{
        public int data3 = 3;
        private int data4 = 4;
        public static int data5; // 可以不加final修饰，可以不用先初始化
        public InsideClass(){
            System.out.println(OutClass.data3);//只能访问外部静态的变量
            OutClass out = new OutClass();
            out.fun1();//访问外部非静态成员
            System.out.println("静态内部类构造方法！");
        }
        public void fun2(){
            System.out.println("静态内部类成员方法！");
        }
    }
    public void fun1(){
        System.out.println(InsideClass.data5);//没引入内部类对象前只能访问静态变量
        OutClass.InsideClass inside = new OutClass.InsideClass();
        System.out.println(inside.data3);//访问静态内部类
        System.out.println("外部类的成员方法！");
    }

}
public class Test{
    public static void main(String[] args){
        //创建静态内部类对象时不需要先创建外部类对象
        OutClass.InsideClass inside = new OutClass.InsideClass();
    }
}*/

/*
class OutClass{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    public OutClass(){
        System.out.println("外部类构造方法！");
    }
    public void fun(){
        System.out.println("外部类成员方法！");
        //局部内部类
        class InsideClass{
            public void fun(){
                System.out.println("外部类成员变量:" + data1);
            }
        }
    }

}
public class Test{
    public static void main(String[]  args){
        OutClass out = new OutClass();
        out.fun();
    }
}*/
